#!coding=utf-8

import time
from concurrent.futures import ThreadPoolExecutor,wait,FIRST_COMPLETED
from print_s import print_safe as print

def action(second):
    time.sleep(second)
    print(second)
    return second


lists=[2, 3, 4, 5]
all_task = []
with ThreadPoolExecutor(max_workers=2) as pool:
    for second in lists:
        all_task.append(pool.submit(action, second))

    # 主线程等待第一个线程返回后就继续执行
    wait(all_task, return_when=FIRST_COMPLETED)
    print("----complete-----")
